#!/usr/bin/sh

modprobe vfd
modprobe aotom

if [ -e /var/etc/.firstboot ]; then
   echo "WAIT 3 min" > /dev/vfd
   echo "WAIT 3 min"
   rm /var/etc/.firstboot
   touch /dev/.devfsd
fi

if [ -e /etc/init.d/mountvirtfs ]; then
   /etc/init.d/mountvirtfs start
fi

modprobe e2_proc

if [ ! -e /var/etc/.firstboot ]; then

   echo "Starting DEBUG Interface"
if [ -e /etc/init.d/mountall ]; then
   /etc/init.d/mountall start
fi

   echo "init stmfb"
   modprobe stmcore-display-stx7109c3
   modprobe stmfb display0=720x576-32@60:12m:pal:yuv:yuv;# display1=720x576-16@50:1m:pal:cvbs;

   echo "LOADING MODULES"   
   echo "MODULES" >/dev/vfd

   echo "load a/v firmware"
   /usr/bin/stslave -t st231.0 -R /boot/video.elf
   /usr/bin/stslave -t st231.1 -R /boot/audio.elf

   echo "init embx"
   modprobe embxshell
   modprobe embxmailbox mailbox0=0xb9211000:136:set2 mailbox1=0xb9212000:0 ;
   modprobe embxshm mailbox0=shm:0:7:0x60000000:0:256:256:0:1024:0xa4000000:0x10000000 ;
   modprobe mme_host transport0=shm

   echo "init AVS"
   modprobe avs type=vip1_avs

   player=`cat /proc/stb/player/version`
   if [ $player == 'player179' ]; then
		echo "[rcS] init player 179"
   else
		echo "[rcS] init player 131"
   fi
   modprobe mmelog
   modprobe mpeg2hw mmeName=MPEG2_TRANSFORMER0;
   modprobe ksound
   modprobe p2div64
   modprobe stm_v4l2
   if [ $player == 'player179' ]; then
		modprobe stmvout
		modprobe stmvbi
   fi
   modprobe pseudocard
   
   echo "init frontends"
   #demodelator type: stb0899, stv090x, cx24116, ce6353, tda10023(default stb0899)
   #tuner type: stb6100, stv6110x, sharp7306, sharp6465, lg031(default stb6100)
   modprobe fe-core demod=stv090x tuner=sharp7306;

   echo "init drivers"
   modprobe cimax
   modprobe pti
   if [ $player == 'player179' ]; then
		modprobe stm_monitor
		modprobe stmsysfs
    modprobe stmdvb
   else
    modprobe stmdvb
    modprobe stm_monitor
   fi	
   modprobe player2
   modprobe sth264pp
   modprobe stmalloc
   modprobe platform
   modprobe smartcard

   showiframe -p /usr/share/bootlogo.mvi &
   stfbcontrol a 0

   echo "init frontpanel"
   modprobe boxtype
   modprobe simu_button

   echo "init lircd"
   mkdir -p /var/run/lirc
   /usr/bin/lircd

   mknod /dev/rc c 147 1 
   mknod /dev/sci0 c 169 0
   mknod /dev/sci1 c 169 1 
   
   /usr/bin/evremote2 vip2 &

   #fix this later if we got to manage a marusys raw device driver
   mount /dev/sda3 /hdd/

   if [ -e /etc/init.d/portmap ]; then
   /etc/init.d/portmap start
fi
if [ -e /etc/init.d/vsftpd ]; then
   /etc/init.d/vsftpd start
fi
   /usr/sbin/inetd

   #timefix e2
   date -s "200901011200"

   stfbcontrol a 255

   echo "ENIGMA 2" > /dev/vfd
   echo "LOADING e2"

   until false
   do
      echo "starting e2->"
      /usr/bin/enigma2
      rtv=$?
      echo "e2 ended <- RTV: " $rtv
      case "$rtv" in
		0) echo "0"
		   echo "E2 ERROR"
      		   reboot;;
		1) echo "1"
		   echo "SHUTDOWN"
                   umount -a;;
		2) echo "2"
		   echo "REBOOT"
		   reboot;;
		3) echo "3"
		   echo "E2 RESTART"
		   echo "0" > /proc/progress
		   showiframe -p /usr/share/bootlogo.mvi &;;
		*) echo "*"
		   echo "ERROR"
                   reboot;;
      esac
   done 
fi
